package basics.day16.demo;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;
import java.util.Date;

public class Test {
    public static void main(String[] args) throws Exception {
        // fun_1();
        // fun_2();
        fun_3();
    }

    /*
     * 闰年判断
     */
    public static void fun_3() {
        Scanner s = new Scanner(System.in);
        System.out.println("请输入需要判断的年份：");
        int year = s.nextInt();
        Calendar c = Calendar.getInstance();
        c.set(year, 2, 1);
        c.add(Calendar.DAY_OF_MONTH, -1);
        int day = c.get(Calendar.DAY_OF_MONTH);
        System.out.println(year + "年二月份" + day + "天");
        if (day == 29) {
            System.out.println(year + "年是闰年");
        } else {
            System.out.println(year + "年是平年");
        }
    }

    /*
     * 出生天数
     * 使用Calendar
     * */
    public static void fun_2() {
        Scanner s = new Scanner(System.in);
        SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd");
        System.out.println("请输入您的出生 年 月 日，格式：yyyy-MM-dd");
        String birthString = s.next();
        String[] birthArr = birthString.split("-");
        Calendar birthCalendar = Calendar.getInstance();
        birthCalendar.set(Integer.parseInt(birthArr[0]), Integer.parseInt(birthArr[1]) - 1, Integer.parseInt(birthArr[2]));
        Calendar nowCalendar = Calendar.getInstance();
        System.out.println("您出生了：" + (nowCalendar.getTime().getTime() - birthCalendar.getTime().getTime()) / 1000 / 60 / 60 / 24 + "天");
    }

    /*
     * 出生天数
     * 使用SimpleDateFormat
     * */
    public static void fun_1() throws Exception {
        Scanner s = new Scanner(System.in);
        SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd");
        System.out.println("请输入您的出生年月日，格式：yyyy-MM-dd");
        String birthString = s.next();
        Date birthDate = sdf.parse(birthString);
        Date nowDate = new Date();
        System.out.println("您出生了：" + (nowDate.getTime() - birthDate.getTime()) / 1000 / 60 / 60 / 24 + "天");

    }
}
